//
//  SGJTabController.m
//  Sewage
//
//  Created by 宗庆猛 on 2017/5/26.
//  Copyright © 2017年 宗庆猛. All rights reserved.
//

#import "SGJTabController.h"
#import "SGJNavController.h"

@interface SGJTabController ()

@end

@implementation SGJTabController

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加子控件器
    UIViewController *homeController = [self controllerWith:@"SGJHomeController" title:@"首页" imageName:@"TabBar_Home"];
    UIViewController *taskController = [self controllerWith:@"SGJTaskController" title:@"任务" imageName:@"TabBar_Task"];
    UIViewController *walletController = [self controllerWith:@"SGJWalletController" title:@"钱包" imageName:@"TabBar_Wallet"];
    UIViewController *mineController = [self controllerWith:@"SGJMineController" title:@"我的" imageName:@"TabBar_Mine"];
    
    self.viewControllers=@[homeController,taskController,walletController,mineController];
    
}
// 后续在ViewController用xib调用
-(UIViewController *)controllerWithStoryboard:(NSString *)storyboardName title:(NSString*) title imageName:(NSString *)imageName{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
    UIViewController *businessController = [sb instantiateInitialViewController];
    
    return [self controller:businessController WithTitle:title imageName:imageName];
}
-(UIViewController *)controllerWith:(NSString *)className title:(NSString *)title imageName:(NSString *)imageName{
    // 根据类名返回对象
    Class clz = NSClassFromString(className);
    UIViewController *controller = [[clz alloc]init];
    
    return [self controller:controller WithTitle:title imageName:imageName];
}
- (UIViewController *)controller:(UIViewController *)controller WithTitle:(NSString *)title imageName:(NSString *)imageName{
    
    controller.tabBarItem.title = title;
    controller.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    controller.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_Sel",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    SGJNavController *navController = [[SGJNavController alloc]initWithRootViewController:controller];
    
    
    return navController;
}


@end
